package dyyx.simplerpc;


public class DefaultFuture {
    private RpcResponse rpcResponse;
    private volatile boolean success = false;
    private final Object object = new Object();
 
    public RpcResponse getRpcResponse(int timeout) throws InterruptedException {
        synchronized (object) {
            while (!success) {
                    object.wait(timeout);
               
            }
            return rpcResponse;
        }
    }
 
    public void setResponse(RpcResponse response) {
        if (success) {
            return;
        }
        synchronized (object) {
            this.rpcResponse = response;
            this.success = true;
            object.notify();
        }
    }
}

